<?php
header("Content-type: text/html; charset=utf-8");
include 'Config.php';
include_once 'Request/V20170525/SendSmsRequest.php';
include_once 'Request/V20170525/QuerySendDetailsRequest.php';

function sendSms($mobile) {
    
    //此处需要替换成自己的AK信息
    $accessKeyId = "LTAIOte21lOtM5RT";
    //$accessKeyId = "LTAIz0wPeHOkqr5Y";//我的
    $accessKeySecret = "qXAeNx77vV6XfmJcn93VWql5OxQ9FS";
    //$accessKeySecret = "anZSMafQ8TTu62QAVy0TDBvVtAWfTK";//我的
    //短信API产品名
    $product = "Dysmsapi";
    //短信API产品域名
    $domain = "dysmsapi.aliyuncs.com";
    //暂时不支持多Region
    $region = "cn-hangzhou";
    
    //初始化访问的acsCleint
    $profile = DefaultProfile::getProfile($region, $accessKeyId, $accessKeySecret);
    DefaultProfile::addEndpoint("cn-hangzhou", "cn-hangzhou", $product, $domain);
    $acsClient= new DefaultAcsClient($profile);
    
    $request = new Dysmsapi\Request\V20170525\SendSmsRequest;
    //必填-短信接收号码
    $request->setPhoneNumbers($mobile);
    //必填-短信签名
    $request->setSignName("杰匠平台");
     //$request->setSignName("阿鹰个人网站");//我的
    //必填-短信模板Code
    $request->setTemplateCode("SMS_132200036");
    //$request->setTemplateCode("SMS_132150008");//我的
    $s = rand(1000,9999);
    //选填-假如模板中存在变量需要替换则为必填(JSON格式)
    $request->setTemplateParam(json_encode(Array(  // 短信模板中字段的值
            "code"=> $s
            
        )));
    
    //选填-发送短信流水号
    $request->setOutId($s);
    
    //发起访问请求
    $acsResponse = $acsClient->getAcsResponse($request);
    $array =  json_decode(json_encode($acsResponse),true); 
    $array['code'] = $s;
    return $array;
}

function querySendDetails() {
    
    //此处需要替换成自己的AK信息
    $accessKeyId = "yourAccessKeyId";
    $accessKeySecret = "yourAccessKeySecret";
    //短信API产品名
    $product = "Dysmsapi";
    //短信API产品域名
    $domain = "dysmsapi.aliyuncs.com";
    //暂时不支持多Region
    $region = "cn-hangzhou";
    
    //初始化访问的acsCleint
    $profile = DefaultProfile::getProfile($region, $accessKeyId, $accessKeySecret);
    DefaultProfile::addEndpoint("cn-hangzhou", "cn-hangzhou", $product, $domain);
    $acsClient= new DefaultAcsClient($profile);
    
    $request = new Dysmsapi\Request\V20170525\QuerySendDetailsRequest();
    //必填-短信接收号码
    $request->setPhoneNumber("13632374351");
    //选填-短信发送流水号
    $request->setBizId("abcdefgh");
    //必填-短信发送日期，支持近30天记录查询，格式yyyyMMdd
    $request->setSendDate("20170525");
    //必填-分页大小
    $request->setPageSize(10);
    //必填-当前页码
    $request->setContent(1);
    
    //发起访问请求
    $acsResponse = $acsClient->getAcsResponse($request);
    var_dump($acsResponse);
    
}


if($_POST){
$mobile = $_POST['moblie'];

$arr = sendSms($mobile);

Session_start(); 
$_SESSION[$mobile] = $arr;
var_dump($_SESSION[$mobile]);
}
?>